class Solution(object):
    def romanToInt(self, s):
        """
        :type s: str
        :rtype: int
        """
        s = list(s)
        s.reverse()
        nDict = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000 }
        last = 0
        acc = 0
        for n in map(lambda r:nDict[r], s):
            if n>=last: acc += n
            else: acc -= n
            last = n
        return acc